home *** CD-ROM | disk | FTP | other *** search
/ Gamers Delight 2 / Gamers Delight 2.iso / Aminet / game / role / ZIP_1_0.lha / src / zip.c < prev    next >
C/C++ Source or Header  |  1992-10-13  |  4KB  |  163 lines

  1. /*
  2.  * zip.c
  3.  *
  4.  * Z code interpreter main routine. Plays Infocom type 3 and 4 games.
  5.  *
  6.  * Usage: zip story-file-name
  7.  *
  8.  * This is a no bells and whistles Infocom interpreter for type 3 and 4 games.
  9.  * It will automatically detect which type of game you want to play. It should
  10.  * support all type 3 and 4 features and is based loosely on the MS-DOS version
  11.  * with enhancements to aid portability. Read the readme.1st file for
  12.  * information on building this program on your favourite operating system.
  13.  * Please mail me, at the address below, if you find bugs in the code.
  14.  *
  15.  * Special thanks to David Doherty and Olaf Barthel for testing this program
  16.  * and providing invaluable help and code to aid its portability.
  17.  *
  18.  * Mark Howell 28-Jul-92 V1.0 howell_ma@movies.enet.dec.com
  19.  *
  20.  * Disclaimer:
  21.  *
  22.  * You are expressly forbidden to use this program if in so doing you violate
  23.  * the copyright notice supplied with the original Infocom game.
  24.  *
  25.  */
  26.  
  27. #include "ztypes.h"
  28.  
  29. #ifdef __STDC__
  30. static void initialize_dictionary (void);
  31. static void configure (void);
  32. #else
  33. static void initialize_dictionary ();
  34. static void configure ();
  35. #endif
  36.  
  37. /*
  38.  * main
  39.  *
  40.  * Initialise environment, start interpreter, clean up.
  41.  *
  42.  */
  43.  
  44. #ifdef __STDC__
  45. int main (int argc, char *argv[])
  46. #else
  47. int main (argc, argv)
  48. int argc;
  49. char *argv[];
  50. #endif
  51. {
  52.  
  53.     process_arguments (argc, argv);
  54.  
  55.     configure ();
  56.  
  57.     initialize_screen ();
  58.  
  59.     load_cache ();
  60.  
  61.     initialize_dictionary ();
  62.  
  63.     restart ();
  64.  
  65.     if (restore_name != NULL && restore ())
  66.         restart ();
  67.  
  68.     interpret ();
  69.  
  70.     unload_cache ();
  71.  
  72.     close_story ();
  73.  
  74.     close_script ();
  75.  
  76.     output_nl ();
  77.  
  78.     reset_screen ();
  79.  
  80.     exit (EXIT_SUCCESS);
  81.  
  82.     return (0);
  83.  
  84. }/* main */
  85.  
  86. /*
  87.  * initialize_dictionary
  88.  *
  89.  * Load special word separator list and dictionary information.
  90.  *
  91.  */
  92.  
  93. #ifdef __STDC__
  94. static void initialize_dictionary (void)
  95. #else
  96. static void initialize_dictionary ()
  97. #endif
  98. {
  99.     int i, count, offset;
  100.  
  101.     offset = h_words_offset;
  102.     count = get_byte (offset);
  103.     for (i = 0, offset++; i < count; )
  104.         punctuation[i++] = get_byte (offset++);
  105.     punctuation[i] = '\0';
  106.     entry_size = get_byte (offset++);
  107.     dictionary_size = get_word (offset);
  108.     dictionary_offset = offset + 2;
  109.  
  110. }/* initialize_dictionary */
  111.  
  112. /*
  113.  * configure
  114.  *
  115.  * Initialise global and type specific variables.
  116.  *
  117.  */
  118.  
  119. #ifdef __STDC__
  120. static void configure (void)
  121. #else
  122. static void configure ()
  123. #endif
  124. {
  125.     zbyte_t header[PAGE_SIZE];
  126.  
  127.     read_page (0, header);
  128.     datap = header;
  129.  
  130.     h_type = get_byte (H_TYPE);
  131.  
  132.     if ((h_type != V3 && h_type != V4) || (get_byte (H_CONFIG) & CONFIG_BYTE_SWAPPED))
  133.         fatal ("wrong game or version");
  134.  
  135.     if (h_type == V3) {
  136.         story_scaler = 2;
  137.         story_shift = 1;
  138.         property_mask = P3_MAX_PROPERTIES - 1;
  139.         property_size_mask = 0xe0;
  140.     } else {
  141.         story_scaler = 4;
  142.         story_shift = 2;
  143.         property_mask = P4_MAX_PROPERTIES - 1;
  144.         property_size_mask = 0x3f;
  145.     }
  146.  
  147.     h_version = get_word (H_VERSION);
  148.     h_data_size = get_word (H_DATA_SIZE);
  149.     h_start_pc = get_word (H_START_PC);
  150.     h_words_offset = get_word (H_WORDS_OFFSET);
  151.     h_objects_offset = get_word (H_OBJECTS_OFFSET);
  152.     h_globals_offset = get_word (H_GLOBALS_OFFSET);
  153.     h_restart_size = get_word (H_RESTART_SIZE);
  154.     h_synonyms_offset = get_word (H_SYNONYMS_OFFSET);
  155.     h_file_size = get_word (H_FILE_SIZE);
  156.     if (h_file_size == 0)
  157.         h_file_size = get_story_size ();
  158.     h_checksum = get_word (H_CHECKSUM);
  159.  
  160.     datap = NULL;
  161.  
  162. }/* configure */
  163.